<?php

namespace app\core\controller;

use think\Controller;
use think\facade\Cache;


class Base extends Controller
{

    public $myInfo = null;

    public function initialize()
    {
        parent::initialize();
        $this->assign('site_name', '划水鸭~~');
        $this->assignUserInfo();
        $this->addTags();
    }


    protected function assignUserInfo()
    {
        if (is_login()) {
            $mid = is_login();
            $myinfo = model('user/User')->getUserInfo($mid);
            $this->assign('myInfo', $myinfo);
            $this->myInfo = $myinfo;
        }
    }


    /**
     * 绑定钩子
     */
    public function addTags()
    {

        $addons = Cache::remember("all_hooks", function () {
            $addons = db('addon')->where('status', 1)->select();
            return $addons;
        });
        foreach ($addons as $v) {
            $hooks = json_decode($v['hooks'], true);
            foreach ($hooks as $k1 => $v1) {
                \think\facade\Hook::add($k1, [$v1]);
            }
        }

    }


    public function checkIsLogin()
    {
        $uid = is_login();
        if (!$uid) {
            $this->error('请登录');
        }
        return $uid;
    }


}
